/*************************************************
//  series in the chart
//  write: xinjian zhang
//  data: 2011/5/10
*************************************************/
#pragma once

#include <vector>
#include "AxisObjects.h"
#include "ChartParam.h"

using namespace std;

class CChart;

class CSeries
{
private:
    CChart *parent;    
public:
    CChartParam param;
    int cellid;
    CString title;
    COLORREF Linecolor;
    vector<CAxisPoint> points;
public:
    
    void Draw(CDC *pdc);

public:

    CSeries(void): Linecolor(0x00ff00)
    {
    }

    CSeries( CChart* parent ): Linecolor(0x00ff00)
    {
        this->parent = parent;
    }

    ~CSeries(void)
    {
    }

    void Add(const float x, const float y)
    {
        points.push_back( CAxisPoint(x,y) );
    }
    
    void Add(CAxisPoint pt)
    {
        points.push_back( pt );
    }

    void Clear()
    {
        points.clear();
    }

public:

    CAxisValue CurrentValue() const;
    CAxisValue GetValue(const int x) const;

    int pointsCount(void) const
    {
        return points.size();
    }

    float maxValue( const float defvalue )
    { 
        float maxvalue = defvalue;
        vector<CAxisPoint>::iterator it;
        for ( it = points.begin(); it != points.end(); it++ )
        {
            if ( (*it).y > maxvalue )
                maxvalue = (*it).y;
        }
        return maxvalue;
    }

    float minValue( const float defvalue )
    {
        float minvalue = defvalue;
        vector<CAxisPoint>::iterator it;
        for ( it = points.begin(); it != points.end(); it++ )
        {
            if ( (*it).y < minvalue )
                minvalue = (*it).y;
        }
        return minvalue;
    }
};
